package com.zlsy.es.dianping.controller;

import com.zlsy.es.dianping.base.R;
import com.zlsy.es.dianping.baseexception.BizException;
import com.zlsy.es.dianping.constan.ErrorStatusEnum;
import com.zlsy.es.dianping.mapper.UserMapper;
import com.zlsy.es.dianping.pojo.model.User;
import com.zlsy.es.dianping.service.EsService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.List;

/**
 * @author zhouliang
 * @date 2020/2/28 23:38
 */
@RequestMapping("/test")
@Controller
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TestController {
    private final UserMapper userMapper;
    private final EsService esService;


    @RequestMapping("/findUsers")
    @ResponseBody
    public R<List<User>> findUsers() {
        return R.success(userMapper.selectAll());
    }

    @RequestMapping("/error")
    @ResponseBody
    public void error() {
        throw new BizException(ErrorStatusEnum.BIND_EXCEPTION_ERROR);
    }

    @RequestMapping("/index")
    public ModelAndView index() {
        String userName = "zlsy";
        ModelAndView modelAndView = new ModelAndView("/index.html");
        modelAndView.addObject("name", userName);
        return modelAndView;
    }

}
